#!/usr/bin/perl
# Version 0.2.1

$testcase = "retrans_unicast";

# 1 = PASS
# 2 = FAIL
# 3 = INCONCLUSIVE
$verdict = 3;

$dumpfile = "$testcase.dump";
$logfile = "$testcase.log";

if ($#ARGV ne 1) {
        print("Usage: $testcase.pl dump_file log_file");
        exit 1;
}

$dumpfile = $ARGV[0];
$logfile = $ARGV[1];

#------------------------------------------------------------------------------

$success = 1;
$state = 0;

open(DUMPFILE, $dumpfile) or $success = 0;

if($success eq 1) {
	
	$last_retr = 0;
	
	while(<DUMPFILE>) {
		# wait 50 s
		if($state eq 0) {
			@l = split(/ /, $_);
		
			# now look at the time
			@ti = split(/\./, $l[0]);
			@ts = split(/:/, $ti[0]);
			
			$secs = $ts[2] + ($ts[1] + $ts[0] * 60) * 60; # secs contains the sim time in seconds
			
			if( $secs > 50) {
				$state = 1;
			}
		} else {
			# wait for 0.0.0.1's updates
			if(/0\.0\.0\.1 > (.*): OSPFv2-ls_upd (.*) rtr 0\.0\.0\.1/) {
				if($state eq 1) {
					# the first update...
					$state = 2;
				} elsif($state eq 2) {
					if($1 ne "0.0.0.2") {
						# not unicast address? bad!
						$state = 3;
					}
				}
			}
		}
	}
	
	close(DUMPFILE);
	
	if($state ne 2) {
		$verdict = 2;
	} else {
		$verdict = 1;
	}
}

if($verdict eq 1) {
	print("LSA retransmission is sent unicast. Test PASSED.\n");
} elsif($verdict eq 2) {
	print("Retransmission not unicast ($state). Test FAILED.\n");
} else {
	print("Cannot determine test results. Test INCONCLUSIVE.\n");
}

#------------------------------------------------------------------------------
print("### VERDICT for $testcase: ");

if ($verdict eq 1) { 
        print("PASS"); 
} elsif ($verdict eq 2) {
        print("FAIL");
} else {
        print("INCONCLUSIVE");
}

print(" ###\n");